/*
 *  Copyright (C) 2010 Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * TreeCellPanel.java
 *
 * Created on 29/11/2010, 23:37:08
 */
package kuasar.plugin.vmcreator.gui.tooltasks.AddHost;

import java.awt.Component;
import java.util.HashMap;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellRenderer;

/**
 *
 * @author jnavalon
 */
public class TreeCellModRenderer extends javax.swing.JPanel implements TreeCellRenderer {

    /** Creates new form TreeCellPanel */
    public TreeCellModRenderer() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbl_cell = new javax.swing.JLabel();

        setOpaque(false);

        lbl_cell.setForeground(new java.awt.Color(204, 204, 204));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lbl_cell, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lbl_cell, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lbl_cell;
    // End of variables declaration//GEN-END:variables

    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {

        Object data[] = (Object[]) ((DefaultMutableTreeNode) value).getUserObject();
        int module = (Integer) data[0];
        boolean isdevice = (Boolean) ((HashMap) data[2]).get("isdevice");
        ImageIcon icon = null;
        if (isdevice) {
            int device = (Integer) ((HashMap) data[2]).get("id");
            switch (device) {
                case 0:
                    icon = new ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/cd_device.png"));
                    break;
                case 1:
                    icon = new ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/hdd_device.png"));
                    break;
                case 2:
                    icon = new ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/floppy_device.png"));
                    break;
            }
        } else {
            switch (module) {
                case -1:
                    icon = new ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/computer.png"));
                    break;
                case 0:
                    icon = new ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/ide.png"));
                    break;
                case 1:
                case 3:
                    icon = new ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/sata.png"));
                    break;
                case 2:
                    icon = new ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/scsi.png"));
                    break;
                case 4:
                    icon = new ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/floppy.png"));
                    break;
                default:
                    icon = new ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/floppy.png"));
            }
        }
        lbl_cell.setIcon(icon);
        lbl_cell.setText((String) data[1]);
        return this;
    }
}
